﻿using System;
using System.Web;
using System.Text; 

namespace Bussiness
{
    public class PermissionModule : IHttpModule
    {
        /// <summary>
        /// You will need to configure this module in the web.config file of your
        /// web and register it with IIS before being able to use it. For more information
        /// see the following link: http://go.microsoft.com/?linkid=8101007
        /// </summary>
        #region IHttpModule Members

        public void Dispose()
        {
            //clean-up code here.
        }

        public void Init(HttpApplication context)
        {
            // Below is an example of how you can handle LogRequest event and provide 
            // custom logging implementation for it
            //context.LogRequest += new EventHandler(OnLogRequest);
            context.BeginRequest += new EventHandler(OnBeginRequest);
        }

        #endregion
        public void OnBeginRequest(Object source, EventArgs e)
        {
             
            if (!Permission.CheckCookiePermission())
            {
                string curUrl = HttpContext.Current.Request.Url.AbsoluteUri;
                if (curUrl.Contains("/PermissionCenterServices/Account/SignInPage.aspx")) return;
                string redUrl = "http://localhost/Ecommerce/PermissionCenterServices/Account/SignInPage.aspx?ru=" + HttpUtility.UrlEncode(curUrl);

                HttpContext.Current.Response.Redirect(redUrl);
                HttpContext.Current.Response.End();
            }
        }
        public void OnLogRequest(Object source, EventArgs e)
        {
            //custom logging logic can go here
          
        }
    }
}
